$value) {
$$key = $value;
}
reset($_GET);
foreach ($_POST as $key => $value) {
$$key = $value;
}
reset($_POST);
if ($_GET[‘Offset’]) {
$Offset = $_GET[‘Offset’];
} else if ($_POST[‘Offset’]) {
$Offset = $_POST[‘Offset’];
} else {
$Offset = 0;
}
if ($_GET[‘Limit’]) {
$Limit = $_GET[‘Limit’];
} else if ($_POST[‘Limit’]) {
$Limit = $_POST[‘Limit’];
} else {
$Limit = 12;
}
if ($_GET[‘Prop_Type_res0’]) {
$_GET[‘Prop_Type_res’][0] = $_GET[‘Prop_Type_res0’];
$_POST[‘Prop_Type_res’][0] = $_GET[‘Prop_Type_res0’];
$key = “Prop_Type_res[0]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_res0’]).”&”;
}
if ($_GET[‘Prop_Type_res’][0]) {
$_POST[‘Prop_Type_res’][0] = $_GET[‘Prop_Type_res’][0];
$key = “Prop_Type_res[0]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_res0’]).”&”;
}
if ($_GET[‘Prop_Type_res1’]) {
$_GET[‘Prop_Type_res’][1] = $_GET[‘Prop_Type_res1’];
$_POST[‘Prop_Type_res’][1] = $_GET[‘Prop_Type_res1’];
$key = “Prop_Type_res[1]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_res1’]).”&”;
}
if ($_GET[‘Prop_Type_res’][1]) {
$_POST[‘Prop_Type_res’][1] = $_GET[‘Prop_Type_res’][1];
$key = “Prop_Type_res[1]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_res1’]).”&”;
}
if ($_GET[‘Prop_Type_res2’]) {
$_GET[‘Prop_Type_res’][2] = $_GET[‘Prop_Type_res2’];
$_POST[‘Prop_Type_res’][2] = $_GET[‘Prop_Type_res2’];
$key = “Prop_Type_res[2]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_res2’]).”&”;
}
if ($_GET[‘Prop_Type_res’][2]) {
$_POST[‘Prop_Type_res’][2] = $_GET[‘Prop_Type_res’][2];
$key = “Prop_Type_res[2]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_res2’]).”&”;
}
if ($_GET[‘Prop_Type_comm0’]) {
$_GET[‘Prop_Type_comm’][0] = $_GET[‘Prop_Type_comm0’];
$_POST[‘Prop_Type_comm’][0] = $_GET[‘Prop_Type_comm0’];
$key = “Prop_Type_comm[0]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_comm0’]).”&”;
}
if ($_GET[‘Prop_Type_comm’][0]) {
$_POST[‘Prop_Type_comm’][0] = $_GET[‘Prop_Type_comm’][0];
$key = “Prop_Type_comm[0]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_comm0’]).”&”;
}
if ($_GET[‘Prop_Type_comm1’]) {
$_GET[‘Prop_Type_comm’][1] = $_GET[‘Prop_Type_comm1’];
$_POST[‘Prop_Type_comm’][1] = $_GET[‘Prop_Type_comm1’];
$key = “Prop_Type_comm[1]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_comm1’]).”&”;
}
if ($_GET[‘Prop_Type_comm’][1]) {
$_POST[‘Prop_Type_comm’][1] = $_GET[‘Prop_Type_comm’][1];
$key = “Prop_Type_comm[1]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_comm1’]).”&”;
}
if ($_GET[‘Prop_Type_land0’]) {
$_GET[‘Prop_Type_land’][0] = $_GET[‘Prop_Type_land0’];
$_POST[‘Prop_Type_land’][0] = $_GET[‘Prop_Type_land0’];
$key = “Prop_Type_land[0]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_land0’]).”&”;
}
if ($_GET[‘Prop_Type_land’][0]) {
$_POST[‘Prop_Type_land’][0] = $_GET[‘Prop_Type_land’][0];
$key = “Prop_Type_land[0]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_land0’]).”&”;
}
if ($_GET[‘Prop_Type_land1’]) {
$_GET[‘Prop_Type_land’][1] = $_GET[‘Prop_Type_land1’];
$_POST[‘Prop_Type_land’][1] = $_GET[‘Prop_Type_land1’];
$key = “Prop_Type_land[1]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_land1’]).”&”;
}
if ($_GET[‘Prop_Type_land’][1]) {
$_POST[‘Prop_Type_land’][1] = $_GET[‘Prop_Type_land’][1];
$key = “Prop_Type_land[1]”;
$GetPass .= “$key=”.urlencode($_GET[‘Prop_Type_land1’]).”&”;
}
reset($_POST[‘Prop_Type_res’]);
// cycle thru passed areas
if ($_GET[‘Area’]) {
foreach ($_GET[‘Area’] as $key => $value) {
$_POST[‘Area’][$key] = $value;
}
} else {
for($i=0;$i<=11;$i++) {
$thisArea = "Area".$i;
if ($_GET[$thisArea]) {
$_POST['Area'][$i] = $_GET[$thisArea];
$GetPass .= "Area[$i]=".urlencode($_GET[$thisArea])."&";
}
}
}
// cycle thru passed acres
if ($_GET['Number_Acres']) {
foreach ($_GET['Number_Acres'] as $key => $value) {
$_POST[‘Number_Acres’][$key] = $value;
}
} else {
for($i=0;$i<=11;$i++) {
$thisAcres = "Number_Acres".$i;
if ($_GET[$thisAcres]) {
$_POST['Number_Acres'][$i] = $_GET[$thisAcres];
$GetPass .= "Number_Acres[$i]=".urlencode($_GET[$thisAcres])."&";
}
}
}
// cycle thru passed bdrms
if ($_GET['Bedrooms']) {
foreach ($_GET['Bedrooms'] as $key => $value) {
$_POST[‘Bedrooms’][$key] = $value;
}
} else {
for($i=0;$i<=5;$i++) {
$thisBdrm = "Bedrooms".$i;
if ($_GET[$thisBdrm]) {
$_POST['Bedrooms'][$i] = $_GET[$thisBdrm];
$GetPass .= "Bedrooms[$i]=".urlencode($_GET[$thisBdrm])."&";
}
}
}
// cycle thru passed Fl_Baths
if ($_GET['Fl_Baths']) {
foreach ($_GET['Fl_Baths'] as $key => $value) {
$_POST[‘Fl_Baths’][$key] = $value;
}
} else {
for($i=0;$i<=2;$i++) {
$thisBtrm = "Fl_Baths".$i;
if ($_GET[$thisBtrm]) {
$_POST['Fl_Baths'][$i] = $_GET[$thisBtrm];
$GetPass .= "Fl_Baths[$i]=".urlencode($_GET[$thisBtrm])."&";
}
}
}
// cycle thru passed Ttl_Sqft
if ($_GET['TotalSqFt']) {
foreach ($_GET['TotalSqFt'] as $key => $value) {
$_POST[‘TotalSqFt’][$key] = $value;
}
} else {
for($i=0;$i<=4;$i++) {
$thisTtlsqft = "TotalSqFt".$i;
if ($_GET[$thisTtlsqft]) {
$_POST['TotalSqFt'][$i] = $_GET[$thisTtlsqft];
$GetPass .= "TotalSqFt[$i]=".urlencode($_GET[$thisTtlsqft])."&";
}
}
}
// create the conditions for the query
// it's a search on property details
// default to all property classes if none are checked
if ((!$_POST['Prop_Type_res']) and (!$_POST['Prop_Type_comm']) and (!$_POST['Prop_Type_land']) and (!$_GET['Prop_Class'])) {
$Conditions .= "(Prop_Class = 'Residential' OR Prop_Class = 'Commercial' OR Prop_Class = 'Land' OR Prop_Class = 'Farmranch')";
} else {
$Conditions .= "(";
if ($_GET['Prop_Class']=="Residential") {
$Conditions .= "(Prop_Class = 'Residential'";
$Conditions .= ") OR ";
$GetPass .= "Prop_Class=Residential&";
}
if ($_POST['Prop_Type_comm'] || $_GET['Prop_Class']=="Commercial") {
$Conditions .= "(Prop_Class = 'Commercial'";
$Conditions .= ") OR ";
$GetPass .= "Prop_Class=Commercial&";
}
$landRanchFlag = 0;
if ($_POST['Prop_Type_land'] || $_GET['Prop_Class']=="Land") {
if ($_POST['Prop_Type_land']) {
$propTypeLndCond = "";
foreach ($_POST['Prop_Type_land'] as $key => $value) {
if ($value == “Ranch”) {
$landRanchFlag = 1;
$propTypeLndCond .= “Prop_Class = ‘Farmranch’ || “;
$GetPass .= “Prop_Type_land=Ranch&”;
}
}
if ($propTypeLndCond) {
$propTypeLndCond = substr($propTypeLndCond,0,-4);
$Conditions .= “($propTypeLndCond) OR “;
}
}
if (!$landRanchFlag) {
$Conditions .= “(Prop_Class = ‘Land'”;
$Conditions .= “) OR “;
$GetPass .= “Prop_Class=Land&”;
}
}
if ($_POST[‘Prop_Type_res’]) {
$propTypeResCond = “”;
foreach ($_POST[‘Prop_Type_res’] as $key => $value) {
$propTypeResCond .= “Prop_Type = ‘$value’ || “;
$GetPass .= “Prop_Type_res[$key]=$value&”;
if ($value == “Single Family”) {
$propTypeResCond .= “Prop_Type = ‘Single Family’ || Prop_Type = ‘Single Fam w Acc Dwelling’ || Prop_Type = ‘Stick Built’ || Prop_Type = ‘Modular’ || “;
}
if ($value == “Condo”) {
$propTypeResCond .= “Prop_Type = ‘Multi-Family’ || Prop_Type = ‘Townhouse’ || “;
}
}
if ($propTypeResCond) {
$propTypeResCond = substr($propTypeResCond,0,-4);
$Conditions .= “($propTypeResCond) OR “;
}
}
// for the property classes, trim the ‘ OR ‘
$Conditions = substr($Conditions, 0, strlen($Conditions)-4);
$Conditions .= “)”;
}
// then go on to formulate the rest of the query
if ($Asking_Price_from) $Conditions .= ” AND Asking_Price >= ‘$Asking_Price_from'”;
if ($Asking_Price_to) $Conditions .= ” AND Asking_Price <= '$Asking_Price_to'";
$areaStr = "";
$areaCnt = 0;
if ($_POST['Area']) {
foreach ($_POST['Area'] as $key => $value) {
$areaCnt++;
$areaStr .= ” Area = ‘$value’ || “;
if ($value == “Crested Butte Rural”) $areaStr .= ” Area = ‘Mt. Crested Butte Rural’ || “;
$GetPass .= “Area[“.$areaCnt.”]=”.urlencode($value).”&”;
}
if ($areaStr) {
$areaStr = substr($areaStr,0,-4);
$Conditions .= ” AND ($areaStr)”;
}
}
// set areas if none are chosen
if (!$areaStr) {
$Conditions .= ” AND (Area = ‘Crested Butte’ || Area = ‘Crested Butte Rural’ || Area = ‘Mt. Crested Butte Rural’ || Area = ‘Mt. Crested Butte’ || Area = ‘Crested Butte South’ || Area = ‘Kebler Pass’ || Area = ‘Almont’ || Area = ‘Gunnison’ || Area = ‘Gunnison Rural’ || Area = ‘Ohio Creek Area’ || Area = ‘Powderhorn’)”;
}
$sqftConditions = “”;
if ($_POST[‘TotalSqFt’]) {
foreach ($_POST[‘TotalSqFt’] as $key => $value) {
if ($value == “5000+”) {
$sqftConditions .= “(TotalSqFt >= ‘5000’) || “;
} else {
$sqftBits = explode(“-“,$value);
$sqftConditions .= “(TotalSqFt >= ‘$sqftBits[0]’ && TotalSqFt <= '$sqftBits[1]') || ";
}
$GetPass .= "TotalSqFt[$key]=$value&";
}
$sqftConditions = substr($sqftConditions, 0, strlen($sqftConditions)-4);
if ($sqftConditions) $Conditions .= " AND ($sqftConditions)";
}
if ($Number_Acres && !$Prop_Class_land) {
// This works fine for non land properties
foreach ($Number_Acres as $key => $value) {
if ($value) {
$GetPass .= “Number_Acres[$key]=$value&”;
$acreConditions .= “(“;
$Acres = explode(“-“, $value);
$acreConditions .= “Acres >= ‘$Acres[0]'”;
$acreConditions .= ” AND Acres <= '$Acres[1]'";
$acreConditions .= ") || ";
}
}
} else if ($Number_Acres && $Prop_Class_land) {
foreach ($Number_Acres as $key => $value) {
if ($value) {
$GetPass .= “Number_Acres[$key]=$value&”;
if ($value == “-0.5”) $acreConditions .= “Acres = ‘Less than 1’ || “;
if ($value == “0.5-1”) $acreConditions .= “Acres = ‘Less than 1’ || “;
if ($value == “1-5”) $acreConditions .= “Acres = ‘1-5’ || “;
if ($value == “5-10”) $acreConditions .= “Acres = ‘6-10′ || “;
if ($value == “10-40”) $acreConditions .= “Acres = ’11-40′ || “;
if ($value == “40-100”) $acreConditions .= “Acres = ’41+’ || “;
if ($value == “100-10000000000″) $acreConditions .= ” Acres = ’41+’ || “;
}
}
}
$acreConditions = substr($acreConditions, 0, strlen($acreConditions)-4);
if ($acreConditions) $Conditions .= ” AND ($acreConditions)”;
$bdrmStr = “”;
if ($_POST[‘Bedrooms’]) {
foreach ($_POST[‘Bedrooms’] as $key => $value) {
if ($value == “Studio”) {
$bdrmStr .= ” Bedrooms = ‘Studio’ || “;
$GetPass .= “Bedrooms[1]=Studio&”;
}
if ($value == “1”) {
$bdrmStr .= ” Bedrooms = ‘1’ || “;
$GetPass .= “Bedrooms[2]=1&”;
}
if ($value == “2”) {
$bdrmStr .= “Bedrooms = ‘2’ || “;
$GetPass .= “Bedrooms[3]=2&”;
}
if ($value == “3”) {
$bdrmStr .= “Bedrooms = ‘3’ || “;
$GetPass .= “Bedrooms[4]=3&”;
}
if ($value == “4”) {
$bdrmStr .= “Bedrooms = ‘4’ || “;
$GetPass .= “Bedrooms[5]=4&”;
}
if ($value == “5”) {
$bdrmStr .= “Bedrooms = ‘5’ || “;
$GetPass .= “Bedrooms[6]=5&”;
}
}
if ($bdrmStr) {
$bdrmStr = substr($bdrmStr,0,-4);
$Conditions .= ” AND ($bdrmStr)”;
}
}
$btrmStr = “”;
if ($_POST[‘Fl_Baths’]) {
foreach ($_POST[‘Fl_Baths’] as $key => $value) {
if ($value == “2”) {
$btrmStr .= ” Fl_Baths = ‘2’ || “;
$GetPass .= “Fl_Baths[1]=2&”;
}
if ($value == “3”) {
$btrmStr .= ” Fl_Baths = ‘3’ || “;
$GetPass .= “Fl_Baths[2]=3&”;
}
if ($value == “4”) {
$btrmStr .= ” Fl_Baths = ‘4’ || “;
$GetPass .= “Fl_Baths[3]=4&”;
}
}
if ($btrmStr) {
$btrmStr = substr($btrmStr,0,-4);
$Conditions .= ” AND ($btrmStr)”;
}
}
if ($Prop_Type) $Conditions .= ” AND Prop_Type = ‘$Prop_Type'”;
// Array for displaying bedrooms numerically in limited area
$bedDisplayArray[‘Studio’] = “Studio”;
$bedDisplayArray[‘One’] = “1”;
$bedDisplayArray[‘Two’] = “2”;
$bedDisplayArray[‘Three’] = “3”;
$bedDisplayArray[‘Four’] = “4”;
$bedDisplayArray[‘Five’] = “5”;
$bedDisplayArray[‘Six’] = “6”;
$bedDisplayArray[‘Seven’] = “7”;
$bedDisplayArray[‘Eight’] = “8”;
$bedDisplayArray[‘Nine’] = “9”;
$bedDisplayArray[‘Ten Or More’] = “10+”;
$Conditions = $FLConditions;
$db = mysqli_connect(“localhost”, “ramman”, “ippw4rm”, “mlsidx”);
//$Order_By = “Asking_Price DESC”; //For Testing
if (!$Order_By) $Order_By = “Asking_Price DESC”;
//$Limit = 12;
//if (!$Limit) $Limit = 12;
//if (!$Offset) $Offset = 0;
$sql = “SELECT
*
FROM Gunnison_listings_new
WHERE $Conditions
ORDER BY $Order_By
LIMIT $Offset, $Limit
“;
$result = mysqli_query($db,$sql);
//echo ““;
$error_text = mysqli_error($db); if ($error_text) echo ““;
$sqlCount = “SELECT COUNT(*)
FROM Gunnison_listings_new
WHERE $Conditions
LIMIT 50
“;
$resultCount = mysqli_query($db,$sqlCount);
//echo “$sqlCount”;
if ($myrowCount = mysqli_fetch_row($resultCount)) $numListings = $myrowCount[0];
if ($numListings > 500) $numListings = 500;
if ($_GET[‘lastLimit’]) {
$LimitToUse = $_GET[‘lastLimit’];
} else {
$LimitToUse = $Limit;
}
$numpages = (INT)($numListings / $LimitToUse);
if ($numListings % $LimitToUse) $numpages++;
$pageNow = $Offset/$LimitToUse +1;
$nextPage = $pageNow + 1;
$lastPage = $pageNow – 1;
if ($_POST) {
while(list($key,$value)=each($_POST)) {
if (($value) and ($key != “Details_search”) and ($key != “Area”) and ($key != “Ttl_Sqft”) and ($key != “Number_Acres”) and ($key != “Prop_Class_res”) and ($key != “Prop_Class_land”) and ($key != “Prop_Class_comm”) and ($key != “Prop_Class”) and ($key != “Prop_type”) and ($key != “Prop_Type_res”) and ($key != “Bedrooms”) and ($key != “Fl_Baths”) and ($key != “Limit”) and ($key != “lastLimit”)) {
$GetPass .= “$key=”.stripslashes(urlencode($value)).”&”;
}
}
}
if ($_GET) {
while(list($key,$value)=each($_GET)) {
if (($value) and ($key != “Offset”) and ($key != “Area”) and ($key != “Ttl_Sqft”) and ($key != “Number_Acres”) and ($key != “Prop_Class_res”) and ($key != “Prop_Class_land”) and ($key != “Prop_Class_comm”) and ($key != “Prop_Class”) and ($key != “Prop_type”) and ($key != “Prop_Type_res”) and ($key != “Bedrooms”) and ($key != “Fl_Baths”) and ($key != “Limit”) and ($key != “lastLimit”)) {
$GetPass .= “$key=”.urlencode($value).”&”;
}
}
}
for($i=1;$i<=$numpages;$i++) {
$offpass = ($i-1) * $LimitToUse;
if ($i == $pageNow) {
$navText .= "$i “;
} else {
// check for last page
if ($i == $numpages) {
$nextLimit = (500-$offpass);
$lastLimit = $Limit;
} else {
$nextLimit = $LimitToUse;
}
$navText .= “$i “;
}
}
// echo “
$navText
“;
$offpassPrev = $Offset – $Limit;
$offpassNext = $Offset + $Limit;
if ($Offset >= $Limit) {
$navDisplaya .= ““;
} else {
$navDisplaya .= ““;
}
$navDisplay .= “ “;
if (($Offset+$Limit) >= $numListings) {
$navDisplayb .= ““;
} else {
$navDisplayb .= ““;
}
// echo “
$navDisplay
“;
$displayCount = 0;
$colCnt = 1;
while ($myrow = mysqli_fetch_array($result)) {
$displayCount++;
// strip non-alpha numeric chars
$addressProcessed = str_replace(” “,”-“,preg_replace(‘/[^a-zA-Z0-9\s]/’, ”, $myrow[‘Address’]));
$cityProcessed = str_replace(” “,”-“,preg_replace(‘/[^a-zA-Z0-9\s]/’, ”, $myrow[‘City’]));
$stateProcessed = str_replace(” “,”-“,preg_replace(‘/[^a-zA-Z0-9\s]/’, ”, $myrow[‘State’]));
// set details page link
$detailsPgLnk = strtolower($addressProcessed.”-“.$cityProcessed.”-“.$stateProcessed.”-“.$myrow[‘Mls_Num’].”.php”);
// look in custom file for a virtual tour for this property
if ($propTourArr[$myrow[‘Mls_Num’]]) $myrow[‘virtual_tour’] = $propTourArr[$myrow[‘Mls_Num’]];
while(list($key,$value)=each($myrow)){
if ($value && $key != “Remarks” && $key != “virtual_tour” && $key != “virtualTour” && $key != “propertyPageURL” && $key != “propertyPageLinkText” && $value != “SLO”) {
$myrow[$key] = ucwords(strtolower($value));
}
}
$priceShow = number_format($myrow[‘Asking_Price’]);
$imageSourcePath = “http://cren.interactiveproperties.com/images/listings/cren”.$myrow[‘Mls_Num’].”.jpg”;
//——————————————————————————
// check for images
$imgCode = “”;
$imgCheck = “”;
if ($myrow[‘imageLocations’]) {
$imgBits = explode(“|”,$myrow[‘imageLocations’]);
for($i=0;$i